'use strict';

// const Controller = require('egg').Controller;
const BaseController = require('../core/base_controller');

class PersonController extends BaseController {
  async index() {
    // console.log("home")
    // await ctx.service.UploadService()
    // this.ctx.body = '';
  }

  //ctx.SHOP_MACHINE_AMOUNT
  async getGoods() {
    const {
      ctx
    } = this;
    const userId = ctx.request.query.id;
    // console.log(userId, "machineList:");
    const orderCount = await ctx.model.OrderBuy.findAll({
      where: {
        userId: userId
      },          
    })
    // console.log("商品", orderCount);
    const user = await ctx.model.User.findById(Number(userId), {
      attributes: ["buyCount"]
    }) //
    // console.log("machineList:", user)
    let list = ''
    // if (user) {
    //   list = user.dataValues;
    // }
        let orderCountLen=0
         for(let i=0;i<orderCount.length;i++){
          orderCountLen+=orderCount[i].orderCount
         }

    let data={
      buyCount:user.buyCount,//已购买
      orderCount: orderCountLen,//orderCount.orderCount,//下单数
      max: ctx.SHOP_MACHINE_AMOUNT,
      text:"V8新一代AI机器人",
      price:299
    }
    this.success({
      data: data,
    }, "ok")
  }







}

module.exports = PersonController;